package com.wjh.controler;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wjh.bean.PageInfo;
import com.wjh.bean.User;
import com.wjh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class PageController {
    @Autowired
    private UserService service;
    @RequestMapping("/pagelist")
    public String pagelist(@RequestParam(required=true,defaultValue="1") Integer page, HttpServletRequest request, Model model){
        Page <User> page1=PageHelper.startPage(page,5);
        List<User> userlist=service.pagelist();
        PageInfo<User> pageInfo=new PageInfo<>(userlist);
        model.addAttribute("page",pageInfo);
        model.addAttribute("userlist",userlist);
        return "pagelist";
    }
}
